@extends('admin.layouts')
@section('main')
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="id" data-params='{"url": "{{url('admin/messagedel')}}","method":"post","data":"_token={{csrf_token()}}","method":"post","confirm":"true","confirmTest":{"title":"{{trans('config.message')}}","msg":"{{trans('config.btn_text_delete')}}","btn":["{{trans('config.yes')}}","{{trans('config.no')}}"]} }'>
                            <i class="iconfont">&#xe626;</i> {{trans('config.btn_delete')}}
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
@endsection

@section('script')

<script id="list-tpl" type="text/html" data-params='{"url":"{{url('admin/messagelist')}}","method":"post","data":{"_token":"{{csrf_token()}}"},"pageid":"#page"}'>
    <table id="example" class="layui-table lay-even">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="id" lay-filter="check" lay-skin="primary"></th>
            <th width="60">ID</th>
            <th>{{trans('config.name')}}</th>
            <th>{{trans('config.email')}}</th>
            <th>{{trans('config.content')}}</th>
            <th width="160">{{trans('config.operation')}}</th>
        </tr>
        </thead>
        <{# layui.each(d.list, function(index, item){ }>
        <tr>
            <td><input type="checkbox" name="id" value="<{item.id}>" lay-skin="primary"></td>
            <td><{item.id}></td>
            <td><{item.name}></td>
            <td><{item.email}></td>
            <td><{item.content}></td>
            <td>
                <button class="layui-btn layui-btn-mini layui-btn-danger" data-method="del" data-url="{{url('admin/messagedel')}}" data-id="<{item.id}>">
                    <i class="iconfont">&#xe626;</i>{{trans('config.btn_delete')}}
                </button></td>
            </td>
        </tr>
        <{# }); }>
        </tbody>

    </table>
</script>


<script>
    layui.use(['list','jquery'],function() {
        var $ = layui.jquery;

        $(document).on('click','.layui-btn', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        var active={
            del:function(othis){
                var url=$(othis).attr('data-url');
                var id=$(othis).attr('data-id');
                var yesTest="{{trans('config.yes')}}";
                var noTest="{{trans('config.no')}}";
                layer.confirm("{{trans('config.btn_text_delete')}}", {icon: 3, title:"{{trans('config.message')}}"
                    ,btn: [yesTest,noTest]
                }, function(){
                    $.ajax({
                        url:url,
                        type:"post",
                        data:{"id":id,"_token":"{{csrf_token()}}"},
                        beforeSend:function(){
                            layer.load(1);
                        },
                        success:function(data){
                            if(data.status==200){
                                layer.msg("{{trans('config.submit_success')}}");
                                $(othis).parents('tr').remove();
                            }else{
                                layer.msg("{{trans('config.submit_error')}}");
                            }
                        },
                        complete:function(){
                            layer.closeAll('loading');
                        },
                        error:function(){
                            layer.msg("{{trans('config.net_error')}}");
                        }
                    })
                }, function(){
                });
            }
        }
    })
</script>
@endsection